#向用户变量中追加系统命令，防止重启命令失效
echo 'export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games' >>/etc/profile

#新建文件夹，分配资源
mkdir /usr/local/java

#安装Java
cd /usr/local/java
#下载java安装包
curl -o jdk-8u251-linux-x64.tar.gz https://code.aliyun.com/kar/oracle-jdk/raw/3c932f02aa11e79dc39e4a68f5b0483ec1d32abe/jdk-8u251-linux-x64.tar.gz
tar -zxvf jdk-8u251-linux-x64.tar.gz
rm jdk-8u251-linux-x64.tar.gz
#追加java的系统环境变量(所有用户皆可使用)
echo 'export JAVA_HOME=/usr/local/java/jdk1.8.0_251' >>/etc/environment
echo 'export JRE_HOME=/usr/local/java/jdk1.8.0_251/jre' >>/etc/environment
echo 'export CLASSPATH=$CLASSPATH:$JAVA_HOME/lib:$JAVA_HOME/jre/lib' >>/etc/environment
echo 'export PATH=$JAVA_HOME/bin:$JAVA_HOME/jre/bin:$PATH:$HOME/bin' >>/etc/environment
#追加java的用户环境变量
echo 'export JAVA_HOME=/usr/local/java/jdk1.8.0_251' >>/etc/profile
echo 'export JRE_HOME=/usr/local/java/jdk1.8.0_251/jre' >>/etc/profile
echo 'export CLASSPATH=$CLASSPATH:$JAVA_HOME/lib:$JAVA_HOME/jre/lib' >>/etc/profile
echo 'export PATH=$JAVA_HOME/bin:$JAVA_HOME/jre/bin:$PATH:$HOME/bin' >>/etc/profile

#重启
reboot